package com.example.home.attorney.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.home.R;
import com.example.home.attorney.activity.LawyerListPage;
import com.example.home.attorney.bean.LawyerCardListBean;

import java.util.List;

import static com.example.home.tool.StaticActi.ip;

public class LawyerCardListAdapter extends RecyclerView.Adapter<LawyerCardListAdapter.MyServer> {
    private Context context;
    private List<LawyerCardListBean.RowsBean> list;

    public LawyerCardListAdapter(Context context, List<LawyerCardListBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public LawyerCardListAdapter.MyServer onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //填充试图
        View view = LayoutInflater.from(context).inflate(R.layout.item_layers, null);
        return new LawyerCardListAdapter.MyServer(view);
    }

    @Override
    public void onBindViewHolder(@NonNull LawyerCardListAdapter.MyServer holder, int position) {
        Glide.with(context).load(ip + list.get(position).getImgUrl()).into(holder.severTvImg);
        holder.severIvText.setText(list.get(position).getName());
        holder.liLayers.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, LawyerListPage.class);
                context.startActivity(intent);
            }
        });
    }


    @Override
    public int getItemCount() {
        return list == null ? 0 :list.size();
    }

    class MyServer extends RecyclerView.ViewHolder {
        private LinearLayout liLayers;
        private ImageView severTvImg;
        private TextView severIvText;



        public MyServer(@NonNull View itemView) {
            super(itemView);
            liLayers = itemView.findViewById(R.id.li_layers);
            severTvImg = itemView.findViewById(R.id.sever_tv_img);
            severIvText = itemView.findViewById(R.id.sever_iv_text);
        }
    }
}

